<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>admin</title>
<link href="<?php echo $_tpl['css']; ?>admin.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="<?php echo $_tpl['js']; ?>jquery.js"></script>
<script language="javascript">
var flag = new Array();
var selected = 0;
function check()
{
	var item = document.getElementById( "name" );

	if ( item.value == "" )
	{
		alert( "请输入名称" );
		item.focus();
		return false;
	}

	$( "input:checkbox" ).each( function( i ){ if ( this.checked ) selected++ } );

	if ( selected < 1 )
	{
		if ( ! confirm( "角色 " + item.value + " 还没有设置权限，是否仍然提交？" ) )
		{
			return false;
		}
	}

	document.getElementById( "submit" ).disabled = true;
	return true;
}
function select_privilege_type( type_id )
{
	flag[type_id] = ! flag[type_id];
	$( ".privilege_type_" + type_id ).each( function( i ){ this.checked = flag[type_id]; } );
}
</script>
</head>
<body>
<form id="apply" method="post" onsubmit="return check()">
<input type="hidden" name="reference" value="<?php echo $reference; ?>">
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="1">
  <tr>
    <td width="38%" height="20" align="right" bgcolor="#272727">名称</td>
    <td width="62%" height="20" colspan="2" align="left" bgcolor="#272727"><input type="text" name="name" id="name"></td>
  </tr>
	<?php
		$cols = 4;
		$index = 1;
		foreach( $privilege_array as $privilege_type_id => $privilege_data )
		{
			$bgcolor = $index++ % 2 ? '#323232' : '#272727';
			$count = 0;
	?>
	<tr>
		<td align="right" bgcolor="<?php echo $bgcolor; ?>"><script language="javascript">flag['<?php echo $privilege_type_id; ?>'] = false;</script><?php echo $privilege_data['name']; ?> <input type="checkbox" onclick="select_privilege_type('<?php echo $privilege_type_id; ?>');"/> 全选</td>
		<td bgcolor="<?php echo $bgcolor; ?>">
			<table>
	<?php
			foreach( $privilege_data['data'] as $privilege )
			{
				if ( $count++ == 0 )
				{
	?>
				<tr>
	<?php
				}
	?>
					<td><input type="checkbox" name="privilege_id[]" class="privilege_type_<?php echo $privilege['type_id']; ?>" value="<?php echo $privilege['id']; ?>"><?php echo $privilege['name']; ?></td>
	<?php

				if ( $count == $cols )
				{
					$count = 0;
	?>
				</tr>
	<?php
				}
			}
	?>
			</table>
		</td>
	</tr>
	<?php
		}
	?>
  <tr>
    <td height="20" colspan="16" align="center" bgcolor="#000000">
		<table width="40%">
			<tr align="center">
				<td><input class="btn2" type="submit" id="submit" value="提交"></td>
				<td><input class="btn2" type="button" value="返回" onclick="window.location.href='<?php echo $reference; ?>'"></td>
			</tr>
		</table>
	</td>
  </tr>
</table>
</form>
</body>
</html>